package com.guigu.ssm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

@Configuration
@ComponentScan("com.guigu.ssm.serivce.impl")
//开启事务
/*@EnableTransactionManagement*/
//引用配置文件
@Import(MybatiesConfig.class)
public class SpringConfig {

    //初始化事务
    @Bean
    public DataSourceTransactionManager initDataSourceTransactionManager(DataSource dataSource){
        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
        dataSourceTransactionManager.setDataSource(dataSource);
        return dataSourceTransactionManager;
    }
}
